package com.cn;

import liquibase.pro.packaged.A;
import org.flowable.engine.ProcessEngine;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.repository.Deployment;
import org.flowable.task.api.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 设计项目流程的方式
 */
@SpringBootTest
public class flowableTestdemo09 {

    /**
     * 流程说明情况
     * 1.启动任务方式
     * 2.说清情况发送申请
     * 3.查询代办任务
     * 4.进行审批
     * 5.审批结束
     */
    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private RuntimeService runtimeService;

    /**
     * 创建学生管理系统的方式
     */
    @Test
    void startRepositoryService(){
        String path = "process01-基础/学生管理系统.bpmn20.xml";
        String name = "学生管理01";
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource(path)
                .name(name)
                .deploy();
        System.out.println(deploy);
    }

    /**
     * 学生发送审批请求
     */
    @Test
    void startServer(){
        String key = "学生管理01";
        Map<String, Object> map = new HashMap<>();
        map.put("stu","薄田胡");
        map.put("stu01","3");
        map.put("stu02","生病");
        runtimeService.startProcessInstanceByKey(key,map);
    }

    /**
     * 代办列表信息
     */
    @Test
    void taskList(){
        String name = "薄田胡";
        List<Task> list = taskService.createTaskQuery()
                .taskAssignee(name)
                .list();
        System.out.println(list);
    }

    /**
     * 审批是否通过
     */
    @Test
    void taskComp(){
        String id = "";
        Map<String, Object> map = new HashMap<>();
        map.put("stu","薄田胡");
        map.put("stu01","3");
        map.put("stu02","生病");
        taskService.complete(id,map);
    }


}
